import { createRenderer } from '@vue/runtime-core'
import { Container, Graphics, Sprite, Text, Texture } from 'pixi.js'

let catchType
const render = createRenderer({
  createElement(type) {
    let element
    switch (type) {
      case 'Container':
        element = new Container()
        break;
      case 'Sprite': 
        element = new Sprite()
        break
      case 'Integral':
        catchType = element
        element = new Sprite()
        break
    }
    return element
  },
  setElementText(node, text) {
    const ctext = new Text(text)
    if(text.indexOf('积分') >= 0) {
      node.removeChildren()
    }
    node.addChild(ctext)
  },
  patchProp(el, key, preValue, nextValue) {
    switch (key) {
      case 'texture':
        el[key] = Texture.from(nextValue)
        break;
      case 'onClick':
        el.click = nextValue
        break
      default:
        el[key] = nextValue
    }
    
  },
  insert(el, parent) {
    parent.addChild(el)
  },
  createText(text) {
    return new Text(text)
  },
  // // 处理注释
  createComment(){},
  // // 获取父节点
  parentNode(){},
  // // 获取兄弟节点
  nextSibling(){},
  // // 删除节点时调用
  remove(el) {
    const parent = el.parent
    parent && parent.removeChild(el)
  }
})

console.log(render)

export function createApp(App) {
  return render.createApp(App)
}